#!/bin/bash

wd="`pwd`"
. $wd/env


if [ ! -f $wd/tmp/hda.img ]; then
	qemu-img create -f qcow2 $wd/tmp/hda.img 2G
fi
if [ ! -f $wd/tmp/hdb.img ]; then
	qemu-img create -f qcow2 $wd/tmp/hdb.img 2G
fi
if [ ! -f $wd/tmp/sda.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sda.img 2G
fi
if [ ! -f $wd/tmp/sdb.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdb.img 2G
fi
if [ ! -f $wd/tmp/sdc.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdc.img 2G
fi
if [ ! -f $wd/tmp/sdd.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdd.img 2G
fi

if [ ! -f $wd/nemonico.iso ]; then
	echo "ERROR: there is no $wd/nemonico.iso image !!"
	exit 1
fi

echo -n " Boot CD(d) or HD(c) ?: "
read ans
if [ "$ans" = "d" ]; then
	boot=d
elif [ "$ans" = "c" ]; then
	boot=c
fi

chmod 750 $wd/files/qemu-ifup

#qemu 	-nographic -cdrom ./nemonico.iso \
#qemu 	-vnc :1 -cdrom ./nemonico.iso \
echo "Starting qemu..."
qemu 	-std-vga -cdrom ./nemonico.iso \
	-hda $wd/tmp/hda.img -hdb $wd/tmp/hdb.img \
	-net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=$wd/files/qemu-ifup \
	-drive file=$wd/tmp/sda.img,if=scsi,bus=0,unit=2 \
	-drive file=$wd/tmp/sdb.img,if=scsi,bus=0,unit=3 \
	-drive file=$wd/tmp/sdc.img,if=scsi,bus=0,unit=4 \
	-drive file=$wd/tmp/sdd.img,if=scsi,bus=0,unit=5 \
	-kernel-kqemu \
       	-boot $boot -m 128

